package com.ruoyi.rural.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.rural.domain.AddressConfiguration;
import com.ruoyi.rural.service.IAddressConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 地址配置Controller
 * 
 * @author ruoyi
 * @date 2022-02-06
 */
@RestController
@RequestMapping("/addressConfiguration")
public class AddressConfigurationController extends BaseController
{
    @Autowired
    private IAddressConfigurationService addressConfigurationService;

    /**
     * 查询地址配置列表
     */
    @RequiresPermissions("rural:addressConfiguration:list")
    @GetMapping("/list")
    public TableDataInfo list(AddressConfiguration addressConfiguration)
    {
        startPage();
        List<AddressConfiguration> list = addressConfigurationService.selectAddressConfigurationList(addressConfiguration);
        return getDataTable(list);
    }

    /**
     * 导出地址配置列表
     */
    @RequiresPermissions("rural:addressConfiguration:export")
    @Log(title = "地址配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AddressConfiguration addressConfiguration)
    {
        List<AddressConfiguration> list = addressConfigurationService.selectAddressConfigurationList(addressConfiguration);
        ExcelUtil<AddressConfiguration> util = new ExcelUtil<AddressConfiguration>(AddressConfiguration.class);
        util.exportExcel(response, list, "地址配置数据");
    }

    /**
     * 获取地址配置详细信息
     */
    @RequiresPermissions("rural:addressConfiguration:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(addressConfigurationService.selectAddressConfigurationById(id));
    }

    /**
     * 新增地址配置
     */
    @RequiresPermissions("rural:addressConfiguration:add")
    @Log(title = "地址配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AddressConfiguration addressConfiguration)
    {
        return toAjax(addressConfigurationService.insertAddressConfiguration(addressConfiguration));
    }

    /**
     * 修改地址配置
     */
    @RequiresPermissions("rural:addressConfiguration:edit")
    @Log(title = "地址配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AddressConfiguration addressConfiguration)
    {
        return toAjax(addressConfigurationService.updateAddressConfiguration(addressConfiguration));
    }

    /**
     * 删除地址配置
     */
    @RequiresPermissions("rural:addressConfiguration:remove")
    @Log(title = "地址配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(addressConfigurationService.deleteAddressConfigurationByIds(ids));
    }
}
